#include "SDL.h"
#include "SSE.h"
#include "Molino.h"
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	SDL_Event evt;
	
	Molino molino(0);
	Molino molino2(300);
	Molino molino3(600);
	
	vector <Entity *>entidades;
	entidades.push_back(&molino);
	entidades.push_back(&molino2);
	entidades.push_back(&molino3);
	
	SSE::engine().start(800, 600, 32, "Prueba", false);
	
	int ticks = SDL_GetTicks();
	int n_frames_second = 60;
	int n_frames_drawed = 0;
	int n_milliseconds_per_frame = 1000 / n_frames_second;
	
	for(;;)
	{
		SDL_Event event;
		
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_KEYDOWN:
					if(event.key.keysym.sym == SDLK_ESCAPE)
						SSE::engine().stop();
					else if(event.key.keysym.sym == SDLK_1)
						molino.swapDireccion();
					else if(event.key.keysym.sym == SDLK_2)
						molino2.swapDireccion();
					else if(event.key.keysym.sym == SDLK_3)
						molino3.swapDireccion();
				break;
			}
		}
		
		if(n_frames_drawed < ((SDL_GetTicks() - ticks) / n_milliseconds_per_frame) && n_frames_drawed < n_frames_second)
		{
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			molino.gira(1);
			entidades[0]->draw();
			
			molino2.gira(1);
			entidades[1]->draw();
			
			molino3.gira(1);
			entidades[2]->draw();
			
			n_frames_drawed++;
			SSE::engine().flip();
		}
		else if((SDL_GetTicks() - ticks) >= 1000)
		{
			n_frames_drawed = 0;
			ticks = SDL_GetTicks();
		}
	}
	
	return 0;
}
